// 用户相关类型
export interface User {
  id: number
  username: string
  email?: string
  avatar?: string
  role: 'admin' | 'user'
  createdAt: string
  lastLoginAt?: string
}

export interface LoginForm {
  username: string
  password: string
  remember?: boolean
}

export interface LoginResponse {
  token: string
  user: User
  expiresAt: string
}

// 代理相关类型
export interface ProxyConfig {
  id: number
  name: string
  host: string
  port: number
  protocol: 'http' | 'https' | 'socks5'
  isAnonymous: boolean
  isActive: boolean
  auth?: {
    username: string
    password: string
  }
  loadBalance?: 'round_robin' | 'least_connections' | 'ip_hash'
  createdAt: string
  updatedAt: string
  description?: string
}

export interface ProxyForm extends Omit<ProxyConfig, 'id' | 'createdAt' | 'updatedAt'> {}

// 统计相关类型
export interface AccessStats {
  totalRequests: number
  totalTraffic: number // 单位：字节
  successRate: number // 成功率百分比
  avgResponseTime: number // 平均响应时间（毫秒）
  onlineProxies: number
  totalProxies: number
}

export interface TrafficData {
  date: string
  requests: number
  traffic: number
  successRequests: number
}

export interface ProxyUsageData {
  proxyId: number
  proxyName: string
  requests: number
  traffic: number
  successRate: number
}

// 日志相关类型
export interface AccessLog {
  id: number
  proxyId: number
  proxyName: string
  clientIp: string
  targetUrl: string
  method: string
  statusCode: number
  requestTime: string
  responseTime: number // 响应时间（毫秒）
  userAgent?: string
  traffic: number // 流量大小（字节）
}

export interface LogQuery {
  proxyId?: number
  clientIp?: string
  method?: string
  statusCode?: number
  startDate?: string
  endDate?: string
  page: number
  pageSize: number
}

// 系统设置相关类型
export interface SystemSettings {
  siteName: string
  maxConnections: number
  defaultTimeout: number
  logRetentionDays: number
  enableAccessLog: boolean
  enableRateLimit: boolean
  rateLimit: {
    requests: number
    window: number // 时间窗口（秒）
  }
}

export interface ChangePasswordForm {
  oldPassword: string
  newPassword: string
  confirmPassword: string
}

// API响应类型
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

export interface PaginatedResponse<T> {
  list: T[]
  total: number
  page: number
  pageSize: number
}

// 通用类型
export interface SelectOption {
  label: string
  value: string | number
}

export interface TableColumn {
  prop: string
  label: string
  width?: string | number
  minWidth?: string | number
  align?: 'left' | 'center' | 'right'
  sortable?: boolean
  formatter?: (row: any, column: any, cellValue: any) => string
}